package com.woniuxy.untis;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;

import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;

public class MessageEncoder implements Encoder.Text<ChatMessage> {
    @SneakyThrows
    @Override
    public String encode(ChatMessage chatMessage) throws EncodeException {
        ObjectMapper mapper = new ObjectMapper();
        return mapper.writeValueAsString(chatMessage);
    }

    @Override
    public void init(EndpointConfig endpointConfig) {
    }

    @Override
    public void destroy() {

    }
}
